<%@ page contentType="text/html; charset=gb2312" %>
<%@ page language="java" %>
<%@ page import="com.mysql.jdbc.Driver" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.text.*" %>
<%

SimpleDateFormat formater = new SimpleDateFormat("yyyy-MM-dd-HH:mm:ss");
String curtime=formater.format(new java.util.Date());

String driverName="com.mysql.jdbc.Driver";
String userName="root";
String userPasswd="111533";
String dbName="myfirst";
String tableName="sensor1";
String url="jdbc:mysql://localhost/"+dbName+"?user="+userName+"&password="+userPasswd;
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection connection=DriverManager.getConnection(url);
for(int i=0;i<80;i++){
Statement statement = connection.createStatement();
 //String sql2="create table sensor"+i+" (id int(7) PRIMARY KEY auto_increment,usbnum int,hum int,tem int,light int,time char(30));";
  String sql2="INSERT INTO sensor"+i+"(usbnum,hum,tem,light,time) VALUES ("+i+", 1600,6100,49,'"+curtime+"');";

statement.executeUpdate(sql2);
statement.close();
}
Statement statement = connection.createStatement();
String sql="SELECT * FROM "+tableName;
ResultSet rs = statement.executeQuery(sql);
ResultSetMetaData rmeta = rs.getMetaData();
int numColumns=rmeta.getColumnCount();
out.print("id");
out.print("|");
out.print("name");
out.print("<br>");
while(rs.next()) {
out.print(rs.getString(1)+" ");
out.print("|");
out.print(rs.getString(2)+" ");
out.print("<br>");
}
out.print("<br>");
out.print("Hello Luo!");
rs.close();
statement.close();
connection.close();
%> 
